<?
require_once("inc_security.php");
//check quyền them sua xoa
checkAddEdit("add");

	//Khai bao Bien
	$after_save_data						= getValue("after_save_data", "str", "POST", "add.php");
	$fac_name								= getValue("fac_name","str","GET","");
    $fac_alias								= getValue("fac_alias","str","GET","");
	$fac_fg_id								= getValue("fac_fg_id","int","GET",'0');
    
    //Call Class generate_form();
	$myform 									= new generate_form();
	//Loại bỏ chuc nang thay the Tag Html
	$myform->removeHTML(0);
	$myform->add("fac_name","fac_name", 0, 0, $fac_name, 1, translate_text("Tên danh mục không được để trống"), 0, "");
    $myform->add("fac_alias","fac_alias", 0, 0, $fac_alias, 1, translate_text("Alias không được để trống"), 0, "");
    $myform->add("fac_fg_id", "fac_fg_id", 1, 0, $fac_fg_id, 1, translate_text("Vui lòng chọn nhóm câu hỏi"),0,"");
    
    $fqgop = get_all_faq_group_options();
	
	//Add table
	$myform->addTable($fs_table);
	//Warning Error!
	$errorMsg = "";
	//Get Action.
	$action	= getValue("action", "str", "POST", "");
	if($action == "execute"){
		$errorMsg .= $myform->checkdata();
		if($errorMsg == ""){
			$db_ex 	= new db_execute_return();
            
			$last_id = $db_ex->db_execute($myform->generate_insert_SQL());
            
			// Redirect to add new
			redirect($after_save_data);
			exit();
		}
	}
	//add form for javacheck
	$myform->addFormname("add_new");
	$myform->evaluate();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<?=$load_header?>
<? $myform->checkjavascript();?>
<script type="text/javascript">
<!--
	function removeAccents(strAccents){
        strAccents = strAccents.split('');
        strAccentsOut = new Array();
        strAccentsLen = strAccents.length;
        var accents = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
        var accentsOut = ['A','A','A','A','A','A','a','a','a','a','a','a','O','O','O','O','O','O','O','o','o','o','o','o','o','E','E','E','E','e','e','e','e','e','C','c','D','I','I','I','I','i','i','i','i','U','U','U','U','u','u','u','u','N','n','S','s','Y','y','y','Z','z'];
        for (var y = 0; y < strAccentsLen && y < 100; y++) {
            if (accents.indexOf(strAccents[y]) != -1) {
                strAccentsOut[y] = accentsOut[accents.indexOf(strAccents[y])];
            }
            else
                strAccentsOut[y] = strAccents[y];
        }
        strAccentsOut = strAccentsOut.join('');
        return strAccentsOut;
    }
    $(document).ready(function(){
        $('#fac_name').keyup(function(){
            var $alias = removeAccents($('#fac_name').val().replace(/ /g, '-'));
            $('#fac_alias').val($alias);
        });
    });
-->
</script>
</head>
<body topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<? /*------------------------------------------------------------------------------------------------*/ ?>
<?=template_top(translate_text("Add_new_category"))?>
<? /*------------------------------------------------------------------------------------------------*/ ?>
	<p align="center" style="padding-left:10px;">
	<?
	$form = new form();
	$form->create_form("faq_add", $_SERVER["REQUEST_URI"], "post", "multipart/form-data",'onsubmit="validateForm(); return false;"');
	$form->create_table();
	?>
	<?=$form->text_note('Những ô dấu (<font class="form_asterisk">*</font>) là bắt buộc phải nhập.')?>
	<?=$form->errorMsg($errorMsg)?>
    
	<?=$form->text("Tên danh mục", "fac_name", "fac_name", $fac_name, "Tên danh mục", 1, 250, "", 255, "", "", "")?>
    <?=$form->text("Alias", "fac_alias", "fac_alias", $fac_alias, "Alias", 1, 250, "", 100, "", "", "")?>
    <?=$form->select("Chọn nhóm", "fac_fg_id", "fac_fg_id", $fqgop, $fac_fg_id, "Chọn nhóm", 0, 250, 1, 0,  "", "")?>
	<?=$form->radio("Sau khi lưu dữ liệu", "add_new" . $form->ec . "return_listing", "after_save_data", $add . $form->ec . $listing, $after_save_data, "Thêm mới" . $form->ec . "Quay về danh sách", 0, $form->ec, "");?>
	<?=$form->button("submit" . $form->ec . "reset", "submit" . $form->ec . "reset", "submit" . $form->ec . "reset", "Cập nhật" . $form->ec . "Làm lại", "Cập nhật" . $form->ec . "Làm lại", 'style="background:url(' . $fs_imagepath . 'button_1.gif) no-repeat"' . $form->ec . 'style="background:url(' . $fs_imagepath . 'button_2.gif)"', "");?>
	<?=$form->hidden("action", "action", "execute", "");?>
	<?
	$form->close_table();
	$form->close_form();
	unset($form);
	?>
	</p>
<?=template_bottom() ?>
<? /*------------------------------------------------------------------------------------------------*/ ?>
</body>
</html>